﻿//<TunynetCopyright>
//--------------------------------------------------------------
//<copyright>青岛拓宇网络科技有限公司 2005-2008</copyright>
//<version>V0.5</verion>
//<createdate>2008-2-22</createdate>
//<author>mazq</author>
//<email>mazq@tunynet.com</email>
//<log date="2008-2-22">创建</log>
//--------------------------------------------------------------
//</TunynetCopyright>


using System;
using System.Collections.Generic;
using System.Text;
using Tunynet.QingdaoCustoms.Common;
using Tunynet.QingdaoCustoms.Caching;
using Tunynet.QingdaoCustoms.Data.Utils;

namespace ChinaCustoms.Qingdao.Workflow.Supports
{
    public class WorkflowInstances
    {
        /// <summary>
        /// 添加Workflow实例
        /// </summary>
        public static void CreateWorkflow(WorkflowInstanceInfo workflowInstanceInfo)
        {
            WorkflowTrackingDataProvider.Instance().CreateUpdateWorkflow(workflowInstanceInfo, DataProviderAction.Create);
        }


        /// <summary>
        /// 更新Workflow实例
        /// </summary>
        public static void UpdateWorkflow(WorkflowInstanceInfo workflowInstanceInfo)
        {
            WorkflowTrackingDataProvider.Instance().CreateUpdateWorkflow(workflowInstanceInfo, DataProviderAction.Update);
        }

        /// <summary>
        /// 获取工作流实例
        /// </summary>        
        public static WorkflowInstanceInfo GetWorkflow(Guid workflowGuid)
        {
            string cacheKey = string.Format("WorkflowInstance:{0}", workflowGuid.ToString());

            WorkflowInstanceInfo workflowInstanceInfo = null;
            workflowInstanceInfo = WebCache.Get(cacheKey) as WorkflowInstanceInfo;

            if (workflowInstanceInfo == null)
            {
                workflowInstanceInfo = WorkflowTrackingDataProvider.Instance().GetWorkflow(workflowGuid);

                WebCache.Insert(cacheKey, workflowInstanceInfo, WebCache.MinuteFactor * 10);
            }

            return workflowInstanceInfo;
        }

    }
}
